package com.demo.controller;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeSet;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.util.ZookeeperClient;

@Controller
@RequestMapping("/")
public class CommonController{
	
	private static Logger logger = LoggerFactory.getLogger(CommonController.class);
	@RequestMapping(value = "showServerNodes", method = RequestMethod.GET)
    @ResponseBody
    public String showServerNodes(HttpServletRequest request) {
    	TreeSet<String> set = new TreeSet<String>();
    	logger.info(request.getSession().toString());
    	Map<String, Integer> serverMap = ZookeeperClient.getServerHost();
    	if(serverMap != null && serverMap.size()>=1){
    		for(Entry<String, Integer> entry :serverMap.entrySet()){
    			set.add(entry.getKey());
    		}
    	}
    	//简单处理页面显示
    	return (set.toString().replace("[", "server nodes :<br>&nbsp;&nbsp;&nbsp;").replace(",", "<br>&nbsp;&nbsp;").replace("]", ""));
    }

}
